package com.demo.rocketmq.config;

import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.acl.common.AclClientRPCHook;
import org.apache.rocketmq.acl.common.SessionCredentials;
import org.apache.rocketmq.remoting.RPCHook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * @author wangfengchen
 */
@Configuration
public class RocketMqConfig {

    @Value("${rocketmq.aclActive:false}")
    private Boolean aclActive;
    @Value("${rocketmq.accessKey:not_set}")
    private String accessKey;
    @Value("${rocketmq.secretKey:not_set}")
    private String secretKey;
    @Value("${rocketmq.namesrvAddr:not_set}")
    private String namesrvAddr;
    @Value("${rocketmq.producer.groupName:defaultProducerGroup}")
    private String defaultProducerGroup;



    // 设置为您在阿里云消息队列RocketMQ版控制台上创建的GID,以及替换为您的AccessKey ID和AccessKey Secret。
    public RPCHook getAclRPCHook() {
        if (StringUtils.isNotEmpty(this.accessKey) && StringUtils.isNotEmpty(this.secretKey)){
            return new AclClientRPCHook(new SessionCredentials(this.accessKey, this.secretKey));
        }
        return null;
    }
    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public String getNamesrvAddr() {
        return namesrvAddr;
    }

    public void setNamesrvAddr(String namesrvAddr) {
        this.namesrvAddr = namesrvAddr;
    }

    public Boolean getAclActive() {
        return aclActive;
    }

    public void setAclActive(Boolean aclActive) {
        this.aclActive = aclActive;
    }

    public String getDefaultProducerGroup() {
        return defaultProducerGroup;
    }

    public void setDefaultProducerGroup(String defaultProducerGroup) {
        this.defaultProducerGroup = defaultProducerGroup;
    }
}
